﻿@{
    ViewBag.Title = "jiesuan";
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
<link href="~/Content/default/jiesuan.css" rel="stylesheet" />
@using System.Data
@using RBS.Common
@model RBS.Web.Hotel.Models.Order.OrderViewModel

<div class="line20"></div>
@using (Ajax.BeginForm("jiesuan", new AjaxOptions { OnSuccess = "OnSuccess" }))
{  
    @Html.HiddenFor(model => model.OrderModel.Id);
    @Html.HiddenFor(model => model.OrderModel.H_Id);
    @Html.HiddenFor(model => model.OrderModel.DineTable);
    @Html.HiddenFor(model => model.OrderModel.U_Id); 
    <table class="ltable">
        <tr>
            <td>结帐单号：@Html.DisplayFor(model => model.Number)</td>
            <td>结账台号：@Model.SeateName</td>
            <td>消费金额：@Model.OrderModel.OrderAmount</td>
        </tr>
    </table> 
    <div class="line20"></div>
    <table class="ltable">
        <tr>
            <td>会员编号/姓名：  @Html.DisplayFor(model => model.User.U_Name)</td>
            <td>就餐人数：  @Html.TextBoxFor(model => model.OrderModel.DineNum, null, new { @class = "input small" }) 人</td>
            <td>会员积分：@Model.UserIntegration</td>
        </tr>
    </table>
    <div class="line20"></div>
   
    <table  class="ltable">
        <tr>
            <td>
                <table width="250">
                    <tr>
                        <td>商品名称</td>
                        <td>单价</td>
                        <td>数量</td>
                        <td>金额</td>
                    </tr>
                    @if (null != ViewData.Model.OrderDetailsModel)
                    {
                        foreach (var item in ViewData.Model.OrderDetailsModel)
                        {
                        <tr>
                            <td>@item.CName</td>
                            <td>@item.Price</td>
                            <td>@item.Num</td>
                            <td>@(item.Price * item.Num)</td>
                        </tr>
                        }
                    }
                </table>

            </td>
            <td>

                <div class="tab-content">

                    <dl>
                        <dt>金额结算	
                        </dt>
                        <dd>
                            <table>
                                <tr>
                                    <td>应付金额：</td>
                                    <td>￥ @Html.TextBoxFor(model => model.OrderModel.OrderAmount, null, new { @class = "input small jine", @readonly = "readonly" })
                                    </td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td>收到金额：</td>
                                    <td>￥ @Html.TextBoxFor(model => model.OrderModel.RecAmount, null, new { @class = "input small jine" })</td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td>优惠金额</td>
                                    <td>￥ @Html.TextBoxFor(model => model.OrderModel.DisAmount, "0", new { @class = "input small jine" }) </td>
                                    <td>优惠金额=积分抵扣+优惠券抵扣
                                    </td>
                                </tr>
                                @{
                    if (Model.User != null)
                    {
                                    <tr>
                                        <td>积分抵扣</td>
                                        <td>￥ @Html.TextBoxFor(model => model.Seetlement.JF, "0", new { @class = "input small jine" })  </td>
                                        <td>
                                            <span class="Validform_checktip">*当前可用积分 @ViewBag.JF，可抵扣金额 @ViewBag.JF1 元</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>优惠券使用</td>
                                        <td>￥ @Html.TextBoxFor(model => model.Seetlement.AdvertisId, "0", new { @class = "input small jine" })
                                        </td>
                                        <td>
                                            @{ 
                                                <ul>
                                                    @if (Model.UserDeed == null)
                                                    {
                                                        <li>无优惠卷信息</li>
                                                    }
                                                    else
                                                    {
                                                        foreach (var row in Model.UserDeed)
                                                        {
                                                        <li>消费满 @row.UseRules 使用 <a href="javascript:;" onclick="UseDeed(@row.Id)">选择</a> </li>     
                                                        }
                                                    }

                                                </ul>
                                            }
                                        </td>
                                    </tr>         } 
                                    <script>
                                        $('#Seetlement_JF').bind('input propertychange', function () {
                                            var a = $("#OrderModel_OrderAmount").val();
                                            var aa = a * 100;
                                            var b = $(this).val();
                                            if (b > aa) {
                                                alert("积分最大输入为：" + aa);
                                                $(this).val(aa);
                                                b = $(this).val();
                                            }
                                            var c = b / 100;
                                            $("#OrderModel_DisAmount").val(c);
                                            $("#OrderModel_AccAmount").val((parseFloat(c) + parseFloat($("#OrderModel_RecAmount").val())) - a);
                                        });

                                        function UseDeed(id) {

                                        }
                                    </script>
                                }
                                <tr>
                                    <td>现金找零：</td>
                                    <td>￥ @Html.TextBoxFor(model => model.OrderModel.AccAmount, null, new { @class = "input small jine", datatype = "ck", @readonly = "readonly", errormsg = "余额不能小于0" })</td>
                                    <td></td>
                                </tr>
                            </table>
                        </dd>
                    </dl>
                </div>
            </td>

            <td>
                <div class="tab-content">
                    <dl>
                        <dt>支付方式</dt>
                        <dd>
                            <div class="rule-single-select">
                                @Html.DropDownListFor(model => model.Seetlement.PayType,
                                                          new[] { new SelectListItem() { Text = "现金", Value = "现金" }, 
                                                              new SelectListItem() { Text = "刷卡", Value = "刷卡" },
                                                          })
                            </div>
                        </dd>
                    </dl>
                    <dl>
                        <dt>店铺优惠券</dt>
                        <dd>
                            <table>
                                <tr>
                                    <th>名称</th>
                                    <th></th>
                                    <th></th>
                                    <th>赠送规则</th>
                                    <th>操作</th>
                                </tr>
                                <tbody id="DeedList"> 
                                   @foreach (var hoteldeed in Model.HotelDeed)
                                   {
                                    <tr>
                                    <td>@hoteldeed.Crowd</td>
                                    <td></td>
                                    <td></td>
                                    <td>赠送规则</td>
                                    <td><a href="javascript:;" onclick="AddUserDeed(@hoteldeed.Id,@Model.User.U_Uid)">赠送</a> </td> 
                                       </tr>
                                   }
                                </tbody>
                            </table>
                        </dd>
                    </dl>
                </div>
                <div class="btn-list">
                    <input type="submit" value="结账" id="btnjiesuan" class="btn" />

                </div>
            </td>
        </tr>
    </table>
  
    <div class="clear"></div>

    
    
    <script>
        /*   $.ajaxSetup({
               async: true
           });*/
        $(function () {
            //加载酒店优惠券
            GetDeed($("#OrderModel_H_Id").val());
            //GetDeed(110);
            //优惠金额
            var a = parseFloat($("#OrderModel_OrderAmount").val());
            var b = parseFloat($('#OrderModel_RecAmount').val());
            var c = parseFloat($('#OrderModel_DisAmount').val());
            $('#OrderModel_DisAmount').bind('input propertychange', function () {
                c = $(this).val();
                if (c == "NaN" || c == null || c == "") {
                    c = 0;
                }
                $("#OrderModel_AccAmount").val((parseFloat(b) + parseFloat(c)) - a);
            });
            //收到金额
            $('#OrderModel_RecAmount').bind('input propertychange', function () {
                b = $(this).val();
                if (c == "NaN" || c == null || c == "") {
                    c = 0;
                }
                //  alert(c);
                $("#OrderModel_AccAmount").val((parseFloat(b) + parseFloat(c)) - a);
            });
            $.extend($.Datatype, {
                "ck": function (gets, obj, curform, regxp) {
                    if (parseInt(gets) < 0) {
                        return false;
                    }
                    return true;
                }
            });
        });
        var isok = false;
        function OnSuccess(s) {
            window.location.href = "@Url.Action("OrderPint", "Print")?orderid=" + s;
        }
       /* function GetDeed(hid) {
            alert(hid);
            $.get("@@Url.Action("SelectDeedList", "Coupons", new { area = "Deed" })?hid=" + hid,
            function (data) {
                $("#DeedList").html("");
                if (data == null)
                    return;
                $.each(data.Data, function (index, row) {
                    row.uid = $("#OrderModel_U_Id").val();
                    var template = $('#DeedTemp').html(); //获取模版的html
                    var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                    $("#DeedList").append(bookData);
                });
            }
            );
        }*/
        function AddUserDeed(a, b) {
            $.get("@Url.Action("Gift", "Coupons", new { area = "Deed" })?uid=" + b + "&apid=" + a,
               function (data) {
                   if (data.Success) {
                       $.dialog.alert("赠送成功");
                   }
               });
        }


    </script> 
    @*<script type="text/template" id="DeedTemp">
        <tr>

            <td>{{Crowd}}</td>
            <td>{{Denomination}}</td>
            <td>{{Quantity}}</td>
            <td>{{AccessRules}}</td>
            <td><a href="javascript:;" onclick="AddUserDeed({{Id}},{{uid}})">赠送</a> </td>
        </tr>
    </script>*@
}